package com.me.forum.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.me.enums.RespType;
import com.me.forum.domain.Page;
import com.me.forum.domain.PageType;
import com.me.forum.domain.User;
import com.me.forum.request.PageRequest;
import com.me.forum.request.PageTypeRequest;
import com.me.forum.request.RemarkRequest;
import com.me.forum.request.UserRequest;
import com.me.forum.service.impl.PageTypeService;
import com.me.forum.utils.components.model.IModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/pagetype")
public class AdminPageTypeController {
	@Autowired
	private PageTypeService pageTypeService;
	
	@GetMapping("/{id}")
	public IModel getById(@PathVariable String id, IModel model) {
		PageType pageType = pageTypeService.findById(id);
		model.put("success", pageType != null);
		model.put("pagetype", pageType);
		return model;
	}
	
	@GetMapping
	public IModel getAllPageType(PageTypeRequest ureq, IModel model, String page, String size) {
		IPage<PageType> PageTypes = pageTypeService.getPageType(ureq, page, size);
		model.success(PageTypes != null && PageTypes.getSize() != 0);
		model.add(RespType.PageTypes, PageTypes);
		return model;
	}
	
	@PostMapping
	public IModel addPageType(@RequestBody PageTypeRequest rreq, IModel model) {
		model.success(pageTypeService.addPageType(rreq));
		return model;
	}
	
	@PutMapping
	public IModel UpdatePageType(@RequestBody PageTypeRequest preq, IModel model) {
		model.success(pageTypeService.UpdatePageType(preq));
		return model;
	}
	
	@DeleteMapping
	private IModel DeletePageType(String id, IModel model) {
		model.success(pageTypeService.delete(id));
		return model;
	}
}
